package com.jsp.web; /**
 * @author wzm
 * @create 2023-05-05 16:12
 */

import com.jsp.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/list")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");

        //准备10个学生
        List<Student> studentList = new ArrayList<>();
        for (int i = 1; i <= 10; i++){
            studentList.add(new Student("name"+i,"phone"+i));
        }
        //将集合存储到request
        request.setAttribute("stuList",studentList);

        //转发到展示页面
        request.getRequestDispatcher("/stuList.jsp").forward(request,response);
    }
}
